/**
* Copyright (C) 2018-2021
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.modules.yktest.service.impl;

import co.yixiang.modules.yktest.domain.YkTestcar;
import co.yixiang.common.service.impl.BaseServiceImpl;
import lombok.AllArgsConstructor;
import co.yixiang.dozer.service.IGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import co.yixiang.common.utils.QueryHelpPlus;
import co.yixiang.utils.ValidationUtil;
import co.yixiang.utils.FileUtil;
import co.yixiang.modules.yktest.service.YkTestcarService;
import co.yixiang.modules.yktest.service.dto.YkTestcarDto;
import co.yixiang.modules.yktest.service.dto.YkTestcarQueryCriteria;
import co.yixiang.modules.yktest.service.mapper.YkTestcarMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import co.yixiang.domain.PageResult;
/**
* @author cy
* @date 2021-06-11
*/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "ykTestcar")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class YkTestcarServiceImpl extends BaseServiceImpl<YkTestcarMapper, YkTestcar> implements YkTestcarService {

    private final IGenerator generator;

    @Override
    //@Cacheable
    public PageResult<YkTestcarDto> queryAll(YkTestcarQueryCriteria criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<YkTestcar> page = new PageInfo<>(queryAll(criteria));
        return generator.convertPageInfo(page,YkTestcarDto.class);
    }


    @Override
    //@Cacheable
    public List<YkTestcar> queryAll(YkTestcarQueryCriteria criteria){
        return baseMapper.selectList(QueryHelpPlus.getPredicate(YkTestcar.class, criteria));
    }


    @Override
    public void download(List<YkTestcarDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (YkTestcarDto ykTestcar : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("汽车名称", ykTestcar.getName());
            map.put("汽车品牌", ykTestcar.getPinpai());
            map.put("产地", ykTestcar.getAddress());
            map.put("添加时间", ykTestcar.getCreateTime());
            map.put(" updateTime",  ykTestcar.getUpdateTime());
            map.put(" isDel",  ykTestcar.getIsDel());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
